import java.io.File;
import java.io.IOException;
import java.util.Calendar;

public class Util {
	private static String space = " ";
	private static String plot = "\\.";
	private static String colon = ":";
	private static int HOUR_IN_SEC = 60 * 60;
	private static int MIN_IN_SEC = 60;

	public static String[] splitWithSpace2A(String str) {
		String[] textArr = null;
		textArr = str.split(space);
		return textArr;
	}

	public static String[] splitWithPlot2A(String str) {
		String[] textArr = null;
		textArr = str.split(plot);
		return textArr;
	}

	public static String[] splitWithColon3A(String str) {
		String[] textArr = null;
		textArr = str.split(colon);
		return textArr;
	}

	public static void writeLog(String str) throws IOException {
		str = String.format(str);
		System.out.println(str);
		new WriteFile(str, Config.LOG_PATH);
	}

	public static void deleteLog() {
		File f = new File(Config.LOG_PATH);
		boolean isDelete = false;
		if (f.exists()) {
			isDelete = f.delete();
		}
		
		if(isDelete){
			System.out.println(" -- Log file is deleted! -- ");
		}
	}

	public static int getHOUR_IN_SEC() {
		return HOUR_IN_SEC;
	}

	public static void setHOUR_IN_SEC(int hOUR_IN_SEC) {
		HOUR_IN_SEC = hOUR_IN_SEC;
	}

	public static int getMIN_IN_SEC() {
		return MIN_IN_SEC;
	}

	public static void setMIN_IN_SEC(int mIN_IN_SEC) {
		MIN_IN_SEC = mIN_IN_SEC;
	}

	public static String setTimeClass(String timeActual) {
		String[] curr_time = Util.splitWithColon3A(timeActual);
		String hour = curr_time[0];
		if (hour.length() == 1) {
			hour = "0" + hour;
		}
		int minute = Integer.parseInt(curr_time[1]);

		if (minute < 30) {
			return hour + ":00:00";
		} else {
			return hour + ":30:00";
		}
	}

	public static String currentDaysOfWeek(Calendar day) {
		String dayName = "";
		int weekday = day.get(Calendar.DAY_OF_WEEK);

		// System.out.println(day.getTime());
		// System.out.println(weekday + " : " + dateString[0] + "-"+
		// dateString[1] + "-" + dateString[2]);

		switch (weekday) {
		case 1:
			dayName = "Sunday";
			break;
		case 2:
			dayName = "Monday";
			break;
		case 3:
			dayName = "Tuesday";
			break;
		case 4:
			dayName = "Wednesday";
			break;
		case 5:
			dayName = "Thursday";
			break;
		case 6:
			dayName = "Friday";
			break;
		case 7:
			dayName = "Saturday";
			break;
		default:
			dayName = "";
			break;
		}
		return dayName;
	}

}
